package com.mariusz.data.rules;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.mariusz.data.DataContainer;
import com.mariusz.data.dto.Rentier;
import com.mariusz.utils.Formats;

public class EndOfContractRule implements Rule {

	@Override
	public List<String> processMessages(DataContainer dt) {
		List<String> messages = new ArrayList<String>();
		Date d = new Date();
		
		for(Rentier r : dt.getRentiers()){
			Calendar endDate = Calendar.getInstance();
			if(r.getContractEndDate() == null){
				continue;
			}
			endDate.setTime(r.getContractEndDate());
			endDate.add(Calendar.DAY_OF_MONTH,-30);
			
			if(endDate.getTime().before(d)){
				messages.add("Contract for "+r.getName()+" will end on "+Formats.formatDate(r.getContractEndDate())+".");
			}
		}
		
		return messages;
	}

}
